package com.rural.bus;

import org.json.JSONObject;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.EditText;

import com.rural.bus.net.MyHttpUtil;
import com.rural.bus.net.OnNetCallback;
import com.rural.bus.net.Url;
import com.rural.bus.utils.ProgressUtil;

public class FeedbackActivity extends BaseActivity{
	
	private EditText etFeedback;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_feedback);
		
		initView();
		setListeners();
		initData();
	}

	@Override
	protected void initView() {
		
		etFeedback=(EditText) findViewById(R.id.et_feedback);
		mBtMiddle.setVisibility(View.VISIBLE);
		mBtMiddle.setText("投诉建议");
		mBtMiddle.setTextColor(getResources().getColor(R.color.white));
		
		mBtRight.setText("确定");
		mBtRight.setVisibility(View.VISIBLE);
		mBtRight.setTextColor(getResources().getColor(R.color.white));
		
		mImgLeft.setVisibility(View.VISIBLE);
		mImgLeft.setBackgroundResource(R.drawable.back_bg_selector);

	}

	@Override
	protected void initData() {
		if(mCurrentUser==null){
			startActivity(LoginActivity.class);
			finish();
			return;
		}
		
	}

	@Override
	protected void setListeners() {
		
		mImgLeft.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				finish();
			}
		});
		mBtRight.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				String feedback=etFeedback.getText().toString();
				if(TextUtils.isEmpty(feedback)){
					toast("输入为空");
					return;
				}
				ProgressUtil.showProgress(getApplicationContext(), "");
				MyHttpUtil http = new MyHttpUtil();
				http.addBodyParm("userId", "" + mCurrentUser.userId);
				http.addBodyParm("type", "" + 0);  //0 乘客  1 司机
				http.addBodyParm("remarks", "" + feedback);
				http.addBodyParm("name", "" + mCurrentUser.name);
				http.addBodyParm("phpne", "" + mCurrentUser.phone);

				http.send(Url.update_url, new OnNetCallback() {

					@Override
					public void success(JSONObject object) {
						ProgressUtil.closeProgress();
						toast("提交成功");
						FeedbackActivity.this.finish();
					}

					@Override
					public void fail(String error) {
						ProgressUtil.closeProgress();
						toast(error);
					}
				});
			}
		});
	}

}
